import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/pages/record/create/create_view.dart';
import 'package:oramemo/pages/record/recording/recording_view.dart';

import 'second_logic.dart';
import 'second_state.dart';

class SecondPage extends StatefulWidget {
  const SecondPage({super.key});

  @override
  _CustomTabBarState createState() => _CustomTabBarState();
}

class _CustomTabBarState extends State<SecondPage>
    with SingleTickerProviderStateMixin {
  final tabs = ['录音', '创作'];
  late TabController _tabController;

  final SecondLogic logic = Get.put(SecondLogic());
  final SecondState state = Get.find<SecondLogic>().state;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: tabs.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: Get.height,
      color: Colors.white,
      child: SafeArea(
        child: Column(
          children: [
            SizedBox(height: 50.h),
            _tabBar(),
            Expanded(
              child: GetBuilder<SecondLogic>(builder: (logic) {
                return TabBarView(
                  controller: _tabController,
                  children: [
                    const RecordingPage(),CreatePage(),
                  ],
                );
              }),
            ),
          ],
        ),
      ),
    );
  }

  TabBar _tabBar() {
    return TabBar(
      onTap: (tab) {
        print(tab);
      },
      padding: EdgeInsets.only(left: 20.w, right: 130.w),
      dividerHeight: 0,
      labelStyle: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold),
      unselectedLabelStyle:
          TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold),
      labelPadding: EdgeInsets.symmetric(horizontal: 35.w),
      indicatorPadding: EdgeInsets.symmetric(horizontal: 35.w),
      isScrollable: true,
      controller: _tabController,
      unselectedLabelColor: Color(0xFFC8D2E3),
      labelColor: Colours.app_main,
      tabs: tabs
          .map((e) => Tab(
                text: e,
                height: 40.h,
              ))
          .toList(),
    );
  }
}
